package com.company.project.utils;

import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;


public class FileList {
    static List filelist = new ArrayList();
    static  String strPath = new String("D:\\javaProject\\hr_parent\\src\\main\\resources\\static\\file");
    public static void main(String[] args) throws Exception {
        genFile(getFileList(strPath));
    }


    public static List<File> getFileList(String strPath) {
        File dir = new File(strPath);
        File[] files = dir.listFiles(); // 该文件目录下文件全部放入数组
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                String fileName = files[i].getName();
                if (files[i].isDirectory()) { // 判断是文件还是文件夹
                    getFileList(files[i].getAbsolutePath()); // 获取文件绝对路径
                } else {
                    String strFileName = files[i].getAbsolutePath();
                    System.out.println("---" + strFileName);
                    filelist.add(files[i]);
                }
            }


        }
        return filelist;
    }
    public static void genFile(List<File> nameList) throws Exception{
        File file = new File("E:/working/name_list.txt");
        FileWriter fw = new FileWriter(file);
        for(File file1 : nameList) {
            String temp = file1.getName().replaceAll(".jpg", "\r\n");
            fw.write(temp);
            fw.flush();
        }
        fw.close();
    }
}



